Iterating folders

The following script is suppose to count for each module named "My Module" in each folder the total objects who's attribute satisfies the condition as in the script.  The problem with this script is that it counts the totals by folder. 

For example:

folder 1 has My Module with a total of 10 objects that satisfies the condition

folder 2 has 5 objects that satisfies the condition.

The output I am getting is:

folder 1: 10

folder 2: 15 (This should be 5 but it's counting the previous folder total.

Can someone help me identify what I am doing wrong?

Object o
Item i
string modName, fullModName, ObjType, attName, itemType, folderName
Project P = current
Folder f = current

for i in p do{
    folderName = name(f)
 itemType = type i
 if(itemType == "Formal"){
  fullModName = fullName(i)
  modName = name(i)
  if(modName == "MyModule"){
   m = read(fullModName, false)
   for o in m do{
    ObjType = o."Object Type"
    attName = o."testAttribute"
    if(ObjType=="test" && attName == "test method"){
     iReqCount++
    }
   }
  print folderName" There are: " iReqCount++""" Test Methods\n"
  close(m)
  }
 }
}

 


A_Alers - Wed Apr 02 21:55:26 EDT 2014

Re: Iterating folders
PRM - Wed Apr 02 23:44:13 EDT 2014

If I'm not mistaken, you have not reset the iReqCount variable to zero at the end of the loop through objects in a formal module. Consequently its value just keeps on compounding after each time you have looped through a module. Maybe enter iReqCount = 0 between lines 23 and 24 which will reset it back to zero before the object count starts in the next module.

Probably a good idea to also declare iReqCount with all of the other variable decalrations at the top and give it an initial value of zero.

 

Paul Miller
Melbourne Australia 

Re: Iterating folders
llandale - Thu Apr 03 14:08:00 EDT 2014

  • Yes set iCount, but I'd do it near the top between #14 and #15.
  • perhaps print "modName" instead of "folderName".
  • open the standard view: m = read(fullModName, false, true)

Re: Iterating folders
A_Alers - Thu Apr 03 19:48:09 EDT 2014

llandale - Thu Apr 03 14:08:00 EDT 2014

  • Yes set iCount, but I'd do it near the top between #14 and #15.
  • perhaps print "modName" instead of "folderName".
  • open the standard view: m = read(fullModName, false, true)

Thank you both!! It worked!